package com.lcg.liteflow.chain2;

import com.alibaba.fastjson.JSON;
import com.lcg.liteflow.dao.TestUser;
import com.lcg.liteflow.dao.TestUserMapper;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author: LCG
 * @date: 2023-03-22 14:04:14
 * @description:
 **/
@LiteflowComponent("pb")
public class PbCompant2 extends NodeComponent {

    @Autowired
    private TestUserMapper testUserMapper;

    @Override
    public void process() throws Exception {


        TestUser testUser = testUserMapper.selectById(1L);

        testUser.setLoginName(testUser.getLoginName()+"COPY0002");

        int updateById = testUserMapper.updateById(testUser);

        System.out.println("===事务的测试==="+updateById);
        if(updateById==1){
            throw new RuntimeException("测试全局回滚出错了");
        }

        ParamMap contextBean = getRequestData();
        System.out.println("bbb->"+ JSON.toJSONString(contextBean));
        contextBean.setResponse("链条最后一步的执行结果，通过写入当前ThreadLocal的方式可以被入口处获取到");
    }
}
